#include "inputtestitem.h"
#include "ui_inputtestitem.h"

InputTestItem::InputTestItem(Input* input,QWidget *parent) :
    QWidget(parent),mInput(input),
    ui(new Ui::InputTestItem)
{
    ui->setupUi(this);
    initWidget();
    connect(mInput,SIGNAL(statusChanged(Input::Status)),this,SLOT(onStChged(Input::Status)));
}

InputTestItem::~InputTestItem()
{
    delete ui;
}

void InputTestItem::initWidget()
{
    ui->labName->setText(QString("X%1:").arg(mInput->getNo()));
    Input::Status status = mInput->getStatus();
    initLabStatus(status);

}

void InputTestItem::initLabStatus(Input::Status status)
{
    if(status ==Input::SET)
    {qDebug()<<__LINE__<<status;
        ui->labOpen->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(31, 233, 51, 255), "
                                   "stop:1 rgba(255, 255, 255, 255));");
        ui->labClose->setStyleSheet("");
    }
    else
    {qDebug()<<__LINE__<<status;
        ui->labClose->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(31, 233, 51, 255), "
                                   "stop:1 rgba(255, 255, 255, 255));");
        ui->labOpen->setStyleSheet("");
    }
}

void InputTestItem::onStChged(Input::Status status)
{qDebug()<<__LINE__<<status;
    initLabStatus(status);
}
